package com.seele.tigerwallet.ui.views;

import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.seele.tigerwallet.R;


/**
 * @Author: 郑波
 *
 * @Time: 2018/6/7 17:40
 *
 * @Description:  首页导航栏图片和文字,提供设置图片和文字,设置文字颜色的功能
 *
 */
public class NavigationChildView extends LinearLayout {


    private ImageView mNavigationImg;//导航栏图片

    private TextView mNavigationTv;//导航栏文字


    public NavigationChildView(Context context) {
        this(context, null);
    }

    public NavigationChildView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public NavigationChildView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    /**
     * 初始化控件
     * @param context
     */
    private void initView(Context context) {
        if (null == context) {
            return;
        }
        View view = View.inflate(context, R.layout.child_navigation_view, this);
        mNavigationImg = view.findViewById(R.id.navigation_img);
        mNavigationTv = view.findViewById(R.id.navigation_tv);

    }


    /**
     * 设置导航栏文字和图片
     * @param drawable
     * @param text
     */

    public  void setNormalNavigationConfig(Drawable drawable, String text,int style ){
        if (null==drawable|| TextUtils.isEmpty(text)){
            return;
        }
        if (null!=mNavigationImg){
            mNavigationImg.setImageDrawable(drawable);
        }
        if (null!=mNavigationTv){
            mNavigationTv.setText(text);
            mNavigationTv .setTypeface(Typeface.defaultFromStyle(style));

        }


    }


    /**
     * 设置导航栏文字和图片
     * @param text
     */

    public  void setNormalNavigationConfig(String text,int style ){

        if (null!=mNavigationTv){
            mNavigationTv.setText(text);
            mNavigationTv .setTypeface(Typeface.defaultFromStyle(style));

        }


    }


    /**
     * 设置导航栏文字和图片
     */

    public  void setNavigationText(int color, int style ){

        if (null!=mNavigationTv){
            mNavigationTv.setTextColor(color);
            mNavigationTv .setTypeface(Typeface.defaultFromStyle(style));

        }


    }


    /**
     * 设置文本颜色
     * @param color
     */
    public void  setTextColor(int color){
        if (null!=mNavigationTv){
            mNavigationTv.setTextColor(color);
        }
    }


    public void setNormalNavigationConfig(int tabIcon, int text, int style) {


        if (null!=mNavigationImg){
            mNavigationImg.setImageResource(tabIcon);
        }
        if (null!=mNavigationTv){
            mNavigationTv.setText(text);
            mNavigationTv .setTypeface(Typeface.defaultFromStyle(style));

        }

    }
}
